package stackAndQueue;

import java.util.Stack;

/**
 * @Author wangtengyu
 * @Create 2018-09-12-14:35 一个函数栈 有函数能够返回栈中最小值 其他功能正常
 */
public class minFunStack {

  //stack1存放正常的数据
  private Stack<Integer> stack1 = new Stack<>();

  //stack2存放每次存放后的最小数
  private Stack<Integer> minStack = new Stack<>();


  public void push(int element) {
    stack1.push(element);
    if (minStack.size() <= 0 || element < minStack.peek()) {
      minStack.push(element);
    } else {
      minStack.push(minStack.peek());
    }
  }


  public int pop() {
    return stack1.pop();
  }


  public int getMin() {
    return minStack.peek();
  }

  public int size() {
    return stack1.size();
  }

  public static void main(String[] args) {
    minFunStack minFunStack = new minFunStack();
    minFunStack.push(3);
    minFunStack.push(2);
    minFunStack.push(-1);
    minFunStack.push(4);
    minFunStack.push(5);

//        while (minFunStack.size()>0) {
//            System.out.println(minFunStack.pop());
//        }
    System.out.println(minFunStack.getMin());

  }


}
